using System.Collections.Generic;
using Crocodile.LangUtils;
using JetBrains.Annotations;



namespace Crocodile.CsharpLanguage.Tree
{
    /// <summary>
    /// Random statement.
    /// </summary>
    public class CsRandomStatement : CsStatement
    {
        private readonly List<string> lines =
            new List<string>();


        /// <summary>
        /// Adds a line to the statement.
        /// </summary>
        /// <param name="text">line to add.</param>
        public void AddText([NotNull] string text)
        {
            lines.AddRange(text.Split('\n'));
        }


        /// <summary>
        /// Adds a line (with insets) to the statement.
        /// </summary>
        /// <param name="template">line template.</param>
        /// <param name="args">parameters for the template.</param>
        public void AddText([NotNull] string template, params object[] args)
        {
            string text = string.Format(template, args);
            AddText(text);
        }


        public override string[] Text
        {
            get { return lines.ToArray(); }
        }


        public override string ToString()
        {
            return lines.JoinAll(s => s, delimiter: "\n", empty: "{}");
        }

    }
}